package com.bing.bean;


import com.bing.mvc.validator.First;
import com.bing.mvc.validator.Forbidden;
import com.bing.mvc.validator.Second;
import com.bing.mvc.validator.Thrid;
import com.bing.utils.StringDataAdapter;
import org.hibernate.validator.constraints.Length;
import org.hibernate.validator.constraints.NotEmpty;

import javax.validation.GroupSequence;
import javax.validation.constraints.Pattern;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;

/**
 * Created by kaibb on 2014/9/30.
 */
@GroupSequence({Second.class,Thrid.class,Person.class})
public class Person {

    @NotEmpty(message = "{user.name.null}",groups = {First.class})
    @Length(message = "",min = 5,max = 9,groups = {First.class})
    @Forbidden()
    @XmlJavaTypeAdapter(StringDataAdapter.class)

    private String name;

    private int age;

    @Pattern(regexp = "[a-zA-Z]{5,20}", message = "{email.invalid}",groups = {Thrid.class})
    @NotEmpty(message = "{email.notnull}",groups = {Second.class})
    private String email;


    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    @Override
    public String toString() {
        final StringBuffer sb = new StringBuffer("Person{");
        sb.append("name='").append(name).append('\'');
        sb.append(", age=").append(age);
        sb.append(", email='").append(email).append('\'');
        sb.append('}');
        return sb.toString();
    }
}
